require("../util.js");
require("../component/components.js");
require("../../jsMt/util.js");
// var userInfo=JSON.parse(localStorage.getItem("userInfo"));
var userCategory=JSON.parse(sessionStorage.getItem("userCategory"));
var vm = new Vue({
    el:"#changeChannel",
    data:{
        txt:"",
        number:10,
        num:0,
        type:"",
        circleId:"",//圈子id
        loginUid:"",//用户id
        categoryId:"",//分类id
        categoryList:{}
    },
    mounted:function(){
        this.searchObject = this.getQueryStringArgs();
        this.circleId=this.searchObject&&this.searchObject.circleId;
        this.loginUid=this.searchObject&&this.searchObject.uid;
        this.type=this.searchObject&&this.searchObject.type;
        this.categoryId=this.searchObject&&this.searchObject.categoryId;
        this.getMainAllCategoryList();
    },
    methods:{
        //后退
        getBack: function () {
            history.go(-1);
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //获取所有自媒体分类信息
        getMainAllCategoryList:function(){
            var that=this;
            this.ajax({url:"/selfMedia/getMainAllCategoryList",dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.categoryList=b.json.data;
                    //console.log(that.categoryList)
                }else{
                    vm.$refs.prompt.toast("获取分类信息列表失败！")
                }
            });

        },
        getNext:function(){

        },
        //修改所属频道
        updateGroupCategory:function(item){
            var that=this;
            if(that.type==1){
                var data={
                    loginUid:that.loginUid,
                    circleId:that.circleId,
                    categoryId:item.categoryId
                };
                this.ajax({url:"/friend/updateGroupCategory",data:data,dataType:"json",method:"post"},function(b){
                    if(b.json.code==0){
                        location.href="/friend/circleSetup?circleId="+that.circleId+"&uid="+that.loginUid;

                        //that.getBack();
                    }else{
                        vm.$refs.prompt.toast("修改失败！");
                    }
                });
            }else if(that.type==2){
                location.href="/friend/foundCircle?categoryId="+item.categoryId+"&name="+encodeURI(item.name);
            }

        }
    },
    watch:{
        txt:function(){
            this.num=this.txt.length;
            //console.log(this.num);
        }
    }
});